package com.zx.scp.utils;

import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Properties;

public class PropertyUtil {
	/**
     * @param args
     */
    public static void main(String[] args) {
        System.out.println(PropertyUtil.getValue("get_policy_url"));

        Date date = new Date();//取时间
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(date);
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        for (int i = 0; i < 31; i++) {
            String dateString = formatter.format(date);
            System.out.println(dateString);
//            getSpringDataSynEachDay(map, routeInfoList, dateString);
            calendar.add(calendar.DATE, 1);//把日期往后增加一天.整数往后推,负数往前移动
            date = calendar.getTime(); //这个时间就是日期往后推一天的结果
        }

    }

    /**
     * 通过key获取配置文件中的value
     *
     * @param key
     * @return
     */
    public static String getValue(String key) {
        Properties property = new Properties();
        try {
            InputStream in = PropertyUtil.class.getClassLoader().getResourceAsStream("Properties.properties");
            property.load(in);
            //属性配置文件自身的编码
            String propertiesFileEncode = "utf-8";
            if(property.getProperty(key)==null){
            	return "";
            }
            return new String(property.getProperty(key).getBytes("ISO-8859-1"), propertiesFileEncode);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}
